package org.example.rowing.service.impl;

import org.example.rowing.domain.Event;
import org.example.rowing.domain.Team;
import org.example.rowing.enums.BoatTypeEnum;
import org.example.rowing.mapper.EventMapper;
import org.example.rowing.mapper.TeamMapper;
import org.example.rowing.service.DataImporter;
import org.example.rowing.service.EventInfoService;
import org.example.rowing.service.TeamInfoService;
import org.example.rowing.vo.EventVO;
import org.example.rowing.vo.TeamVO;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class TeamDataImporter implements DataImporter<Team> {
    private TeamInfoService teamInfoService;
    private EventInfoService eventInfoService;  // 假设我们需要从 Event 表中获取 EventId

    public TeamDataImporter(TeamInfoService teamInfoService, EventInfoService eventInfoService) {
        this.teamInfoService = teamInfoService;
        this.eventInfoService = eventInfoService;
    }

    @Override
    public boolean validate(Team team) {
        // 验证 Team 数据
        if (team.getName() == null || team.getName().isEmpty() || team.getEventId() == null) {
            return false;  // 队伍名称不能为空
        }
        // 可以添加更多的验证逻辑
        Event eventCondition = new Event();
        eventCondition.setId(team.getEventId());
        List<EventVO> eventVOS = eventInfoService.showSearchedEvents(eventCondition);
        return !eventVOS.isEmpty();
    }

    @Override
    public Set<String> selectAliveNames() {
        Set<String> nameSet = new HashSet<>();
        List<TeamVO> teamVOS = teamInfoService.showSearchedTeams(new Team());
        for (TeamVO teamVO : teamVOS) {
            nameSet.add(teamVO.getEventVO().getId() + teamVO.getName());
        }
        return nameSet;
    }
}

